import { ExecutionContext, Injectable } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { Reflector } from "@nestjs/core";
import { IS_PUBLIC_KEY } from '../common/public.decorator';
import { Observable } from "rxjs";

@Injectable()
export class jwtAuthGuard extends AuthGuard('jwt'){
    constructor(private reflector: Reflector){
        super()
    }

    canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
        const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
            context.getHandler(),
            context.getClass()
        ])
        console.log(isPublic, 'isPublic');
        if(isPublic){
            return true;
        }
        return super.canActivate(context);
    }
}